module.exports = class extends think.cmswing.rest {
  /**
   * 付款单
   * @returns {Promise.<*>}
   */
  async getAction() {
    let data;
    const model = this.model('cmswing/category');
    if (this.id) {
      data = await model.where({id: this.id}).find();
      return this.success(data);
    }
    data = await model.get_all_category();
    return this.success(arr_to_tree(data, 0));
  }
  async postAction() {
    think.logger.info('fukuandan-postAction:this.getData()', this.getData());
    const order_id = this.post('order_id');
    const user_id = this.post('user_id');
    const user_gsmc = this.post('user_gsmc');
    const persent = this.post('persent');
    const fukuanjine = this.post('fukuanjine');
    const order = await this.model('order').where({id: order_id}).find();
    const fukuanno = await this.model('cmswing/order').orderid(user_id);
    const map = {};
    /* const data = await this.requestOA('executeQuery', { sql: `select htbh from uf_cghtxx where portalid='${order.order_no}'` });
    if(typeof (data) === 'undefined') {
      return this.fail('OA系统查询合同异常，请重试。');
    }
    if(think.isEmpty(data.data.list)){
      return this.fail({name:'此订单无对应OA合同编号！'});
    }*/
    if (order) {
      map.order_no = order.order_no;
      map.fukuanno = fukuanno;
      map.user_id = user_id;
      map.user_gsmc = user_gsmc;
      map.shoukuan_id = order.gongid;
      map.status = 0;
      map.chuangjianshijian = new Date().valueOf();
      map.persent = persent;
      map.fukuanjine = fukuanjine;
      map.htbh = order.htbh;
    }
    const res = await this.model('fukuandan').add(map);
    const data1 = await this.model('fukuandan').where({id: res}).find();
    think.logger.info('fukuandan-postAction:success', data1);
    return this.success(data1, '编辑成功！');
  }
};
